Міністрество освіти і науки, молоді та спорту України
Національний університет «Львівська політехніка»
Кафедра ЕОМ
Звіт
про виконання лабораторної роботи №5
Львів 2015
//main.cpp
#include <iostream>
#include "GasStation.h"
using namespace std;
int main(){
CGasStation lukoil(10000, 5674, 15000, 6783, 9000, 4536, 11000, 8976, 15), ukrnafta(lukoil);
lukoil.fnArrInit();
while (true){
cout << "\n===================\nget - 1\nadd - 2\nref - 3\nchange - 4\n\+ - 5\nval++ - 6\n++val - 7\n!= - 8\n[] - 9\n===================\n";
int a;
cin >> a;
if ((a != 1) && (a != 2) && (a != 3) && (a != 4) && (a != 5) && (a != 6) && (a != 7) && (a != 8) && (a != 9)) break;
switch (a){
case 1: lukoil.fnGet();
break;
case 2: lukoil.fnAddPatrol();
break;
case 3:lukoil.fnRefuel();
break;
case 4: lukoil.fnChangeTheVolume();
break;
case 5: lukoil + ukrnafta;
lukoil.fnGet();
break;
case 6: (lukoil--).fnGet();
break;
case 7: (--lukoil).fnGet();
break;
case 8: if (lukoil != ukrnafta){
cout << "false" << endl;
}
else{
cout << "true" << endl;
}
break;
case 9: int a;
cout << "Vvedit nomer skhovishcha: ";
cin >> a;
cout << lukoil[a-1]<<endl;
default: break;
}
}
}
//gasstation.h
#pragma once
class CGasStation
{
public:
CGasStation(CGasStation & gas); //копіювання
CGasStation(int iVolume1, int iVolumeOfStocks1, int iVolume2, int iVolumeOfStocks2,
int iVolume3, int iVolumeOfStocks3, int iVolume4, int iVolumeOfStocks4, int iCapacity); //ручна ініціалізація
~CGasStation();
void fnGet(); //вивід
void fnAddPatrol(); //додаю паливо в сховище
void fnRefuel(); //заправка
void fnChangeTheVolume(); //змінюю об'єм сховища
void fnArrInit(); //елементам масиву присвоююю початкові значення залишків палива у сховищі
void operator+(CGasStation & gas); //перевантажую +
CGasStation operator--(int); //перевантажую постфіксний декремент
CGasStation & operator--(); //перевантажую префіксний декремент
bool operator!=(CGasStation & gas);
int & operator[](int index);
int *arr = new int[4];
private:
int m_iVolume1, m_iVolume2, m_iVolume3, m_iVolume4,
m_iVolumeOfStocks1, m_iVolumeOfStocks2, m_iVolumeOfStocks3, m_iVolumeOfStocks4,
m_iCapacity;
};
//gasstation.cpp
#include "GasStation.h"
#include "iostream"
using namespace std;
CGasStation::CGasStation(CGasStation & gas){
m_iVolume1 = gas.m_iVolume1;
m_iVolume2 = gas.m_iVolume2;
m_iVolume3 = gas.m_iVolume3;
m_iVolume4 = gas.m_iVolume4;
m_iVolumeOfStocks1 = gas.m_iVolumeOfStocks1;
m_iVolumeOfStocks2 = gas.m_iVolumeOfStocks2;
m_iVolumeOfStocks3 = gas.m_iVolumeOfStocks3;
m_iVolumeOfStocks4 = gas.m_iVolumeOfStocks4;
m_iCapacity = gas.m_iCapacity;
}
CGasStation::CGasStation(int iVolume1, int iVolumeOfStocks1, int iVolume2, int iVolumeOfStocks2,
int iVolume3, int iVolumeOfStocks3, int iVolume4, int iVolumeOfStocks4, int iCapacity){
m_iVolume1 = iVolume1;
m_iVolume2 = iVolume2;
m_iVolume3 = iVolume3;
m_iVolume4 = iVolume4;
m_iVolumeOfStocks1 = iVolumeOfStocks1;
m_iVolumeOfStocks2 = iVolumeOfStocks2;
m_iVolumeOfStocks3 = iVolumeOfStocks3;
m_iVolumeOfStocks4 = iVolumeOfStocks4;
m_iCapacity = iCapacity;
}
CGasStation::~CGasStation(){
delete[] arr;
}
void CGasStation::fnGet(){
cout << "Type 1: " << "Volume = " << m_iVolume1 << "; VolumeOfStocks = " << m_iVolumeOfStocks1 << ";\n";
cout << "Type 2: " << "Volume = " << m_iVolume2 << "; VolumeOfStocks = " << m_iVolumeOfStocks2 << ";\n";
cout << "Type 3: " << "Volume = " << m_iVolume3 << "; VolumeOfStocks = " << m_iVolumeOfStocks3 << ";\n";
cout << "Type 4: " << "Volume = " << m_iVolume4 << "; VolumeOfStocks = " << m_iVolumeOfStocks4 << ";\n";
cout << "Capacity = " << m_iCapacity << ";\n";
}
void CGasStation::fnAddPatrol(){
int iType; int iVolume;
cout << "Vvedu tup skhovushcha(1,2,3 abo 4): ";
cin >> iType;
cout << "\nVVedu ob'em paluva: ";
cin >> iVo...